﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Mail;
using System.IO;


namespace Controller
{
    public static class BeskedCenter
    {
        public static bool SendSms(int tlf, string besked)
        {
            try
            {
                WebClient client = new WebClient();
                // Add a user agent header in case the requested URI contains a query.
                client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
                client.QueryString.Add("user", "jakobvj");
                client.QueryString.Add("password", "AzyM35Bb");
                client.QueryString.Add("api_id", "3374502");
                client.QueryString.Add("to", "45" + tlf);
                client.QueryString.Add("text", besked);
                client.QueryString.Add("from", "4531202058");
                string baseurl = "http://api.clickatell.com/http/sendmsg";
                Stream data = client.OpenRead(baseurl);
                data.Close();
                return true;
            }
            catch (Exception)
            {
                return false;
                throw;
            }
            
            
        }
        public static bool SendMail(string modtager, string besked)
        {
            try
            {
                MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

                mail.From = new MailAddress("scooterlandnoreply@gmail.com");
                mail.To.Add(modtager);
                mail.Subject = "Besked fra Scooterland";
                mail.Body = besked;

                SmtpServer.Port = 587;
                SmtpServer.Credentials = new System.Net.NetworkCredential("scooterlandnoreply", "gunnernu");
                SmtpServer.EnableSsl = true;

                SmtpServer.Send(mail);
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }


        }
    }
}
